#!/usr/bin/python
"""
Module to simulate a real-time acquisition file.
"""

from time import sleep

def acquisition(input_name, output_name):
    """
    Created : Brent Maranzano
    Last Modified : August 5, 2014
    Function to simulate a running acquisition file. The
    input_name file is a completed acquisition data file. The
    output_name file will be created at runtime with no data,
    followed by periodic appending of data from the input
    file.
    input_name : string filename of the completed acquisition file
    output_name : string filename of the simulated acquisition file
    """
    input_file = open(input_name, mode='r')
    output_file = open(output_name, mode='a')
    line = input_file.readline()
    # Write the header.
    while line.find('[Sensor Monitor]') != 0:
        output_file.write(line)
        line = input_file.readline()
    # Write the "[Sensor Monitor]" line.
    output_file.write(line)
    # Begin writing the data.
    while True:
        line = input_file.readline()
        output_file.write(line)
        output_file.flush()
        sleep(5)
    input_file.close()
    output_file.close()

if __name__ == "__main__":
    import sys
    input_name = sys.argv[1]
    output_name = sys.argv[2]
    acquisition(input_name, output_name)
